define([
  'jquery',
  'views/Modal',
  'views/ModalForm',
  "hbs!template/internals/familiar-modal-embedded",
  "hbs!template/internals/success-familiar-modal",
  'bootstrap_tooltip',
  'bootstrap_popover'
], function($, Modal, ModalForm, template, successTemplate){
  var FamiliarModal = ModalForm.extend({
    initialize: function() {
      console.log("Familiar form modal view");
      console.log(this.model);
      this.template = template;
      ModalForm.prototype.initialize.call(this);
    },
    
    renderContain: function() {
      $(this.el).html(this.template(this.model.toJSON()));
      this.$('[rel="popover"]').popover();
      this.$("#password").click(function() {
        $(this).select();
      });
    },
    
    save: function(){
      console.log("Save in FamiliarModal");
      console.log(this.model);
      console.log("---------------");
      this.model.save(this.getObjectFromForm(this.$("form")));
    },

    showSuccessMessage: function(updated) {
      var modal = new Modal({template: successTemplate, flags: {updated: updated}});
      modal.render();
    }

  });

  return FamiliarModal;
});